using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using SmartLink.DTOS;
using SmartLink.DTOS.Permission;
using SmartLink.Application.IServices;
using SmartLink.Domain;
using SmartLink.Infrastructure.Cache;
using SmartLink.DTOS.Base;
using SmartLink.WebApi.Filter;
using SmartLink.Infrastructure;

namespace SmartLink.WebApi.Controllers.Permission
{
    /// <summary>
    /// 角色管理
    /// </summary>
    public class RoleController : BaseAPIControl
    {
        private IRoleAppServices _roleAppServices;
        public RoleController(IRoleAppServices roleAppServices)
        {
            _roleAppServices = roleAppServices;
        }

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        //[AuthorizeHandle]
        public Results Add([FromBody]RoleAddDTO model)
        {
            return _roleAppServices.AddRole(model);
        }
        /// <summary>
        /// 获取单个角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results Get(IDDTO model)
        {
            return _roleAppServices.GetRole(model.ID);
        }
        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results Update(RoleUpdateDTO model)
        {
            return _roleAppServices.UpdateRole(model);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results Delete(IDDTO model)
        {
            return _roleAppServices.DeleteRole(model.ID);
        }
        /// <summary>
        /// 获取角色列表(分页)
        /// </summary>
        /// <param name="pagePara"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<PageData<RoleListItemDTO>> GetPageList(RolePagePara pagePara)
        {
            return _roleAppServices.GetPageList(pagePara);
        }
        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="model">OID为空则取当前公司数据</param>
        /// <returns></returns>
        [HttpPost]
        public Results<IList<SelectItemDTO>> GetRoleSelectList(OIDDTO_Nullable model)
        {
            return _roleAppServices.GetRoleSelectList(model.OID);
        }

        /// <summary>
        /// 给用户分配角色
        /// </summary>
        /// <param name="allotRoleToUserDTO">一个用户，多个角色</param>
        /// <returns></returns>
        [HttpPost]
        public Results AllotRolesToUser(AllotRoleToUserDTO allotRoleToUserDTO)
        {
            return _roleAppServices.AllotRolesToUser(allotRoleToUserDTO);
        }

        ///// <summary>
        ///// 给角色分配菜单权限
        ///// </summary>
        ///// <param name="allotMenuToRoleDTO"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[NonAction]
        //public Results AllotMenuIdToRole(AllotMenuToRoleDTO allotMenuToRoleDTO)
        //{
        //    return _permissionManagerAppServices.AllotMenuIdToRole(allotMenuToRoleDTO, CurUserInfo.UserId);
        //}
        ///// <summary>
        ///// 给角色分配动作权限
        ///// </summary>
        ///// <param name="allotActionToRoleDTO"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[NonAction]
        //public Results AllotActionsToRole(AllotActionToRoleDTO allotActionToRoleDTO)
        //{
        //    return _permissionManagerAppServices.AllotActionsToRole(allotActionToRoleDTO);
        //}

        ///// <summary>
        ///// 分配数据权限给角色
        ///// </summary>
        ///// <param name="allotDataRightsToRole"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[NonAction]
        //public Results AllotDataRightsToRole(AllotDataRightsToRole allotDataRightsToRole)
        //{
        //    return _permissionManagerAppServices.AllotDataRightsToRole(allotDataRightsToRole);
        //}
    }
}
